import axios from '@/libs/api.request'
import qs from 'qs'

export const getTableData = (params) => {
  return axios.request({
    url: 'admins/admin/page?t='+new Date().getTime(),
    params,
    method: 'get'
  })
}

// 管理员设备分页
export const getTableData2 = (params) => {
  return axios.request({
    url: 'admins/adminEquipment/getListPage?t='+new Date().getTime(),
    params,
    method: 'get'
  })
}
export const add = (data) => {
  return axios.request({
    url: 'admins/admin/add',
    data: qs.stringify(data),
    method: 'post'
  })
}

export const update = (data) => {
  return axios.request({
    url: 'admins/admin/update',
    data: qs.stringify(data),
    method: 'post'
  })
}

export const update_status = (data) => {
  return axios.request({
    url: 'admins/admin/update_status',
    data: qs.stringify(data),
    method: 'post'
  })
}

export const del = (data) => {
  return axios.request({
    url: 'admins/admin/delete',
    data: qs.stringify(data),
    method: 'post'
  })
}

export const login = ({ userName, password }) => {
  const data = {
    username: userName,
    password: password
  }
  return axios.request({
    url: 'admins/passport/login',
    data: qs.stringify(data),
    method: 'post'
  })
}

export const getUserInfo = (token) => {
  return axios.request({
    url: 'get_info?t='+new Date().getTime(),
    params: {
      token
    },
    method: 'get'
  })
}

export const logout = (token) => {
  return axios.request({
    url: 'logout',
    method: 'post'
  })
}

export const getUnreadCount = () => {
  return axios.request({
    url: 'message/count?t='+new Date().getTime(),
    method: 'get'
  })
}

export const getMessage = () => {
  return axios.request({
    url: 'message/init?t='+new Date().getTime(),
    method: 'get'
  })
}

export const getContentByMsgId = msg_id => {
  return axios.request({
    url: 'message/content?t='+new Date().getTime(),
    method: 'get',
    params: {
      msg_id
    }
  })
}

export const hasRead = msg_id => {
  return axios.request({
    url: 'message/has_read',
    method: 'post',
    data: {
      msg_id
    }
  })
}

export const removeReaded = msg_id => {
  return axios.request({
    url: 'message/remove_readed',
    method: 'post',
    data: {
      msg_id
    }
  })
}

export const restoreTrash = msg_id => {
  return axios.request({
    url: 'message/restore',
    method: 'post',
    data: {
      msg_id
    }
  })
}

//给予授权
export const assign = (params) => {
  return axios.request({
    url: 'admins/admin/assign?t='+new Date().getTime(),
    params,
    method: 'get'
  })
}
//取消授权
export const unAssign = (params) => {
  return axios.request({
    url: 'admins/admin/unAssign?t='+new Date().getTime(),
    params,
    method: 'get'
  })
}

export const updatePwd = (data) => {
  return axios.request({
    url: 'admins/admin/updatePwd',
    data: qs.stringify(data),
    method: 'post'
  })
}
